/* Copyright (c) 2009 SpringShowcase, Inc.
 * All right reserved.
 * http://code.google.com/p/springshowcase/
 * This software is the confidential and proprietary information of BeyondWeb
 * , Inc. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license agreement
 * you entered into with BeyondWeb.
 *
 * Revision History
 * Author              Date             Description
 * ------------------   --------------    ------------------
 *  kwondohee           2010. 4. 4.        
 */
package org.springshowcase.mvc;

import java.util.regex.Pattern;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.lang.StringUtils;

public class EmailValidator implements ConstraintValidator<NotEmail, String> {

	private Pattern EMAIL_PATTERN = Pattern.compile(".+@.+\\.[a-z]+");
	
	public void initialize(NotEmail constraintAnnotation) {
		// nothing to initialize
	}
	
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if(StringUtils.isEmpty(value)){
			return false;
		}
		 return EMAIL_PATTERN.matcher(value).matches();
	}
}
